//
//  AppsBaseViewController.m
//  GDPU_Bible
//
//  Created by Vescky on 13-5-31.
//  Copyright (c) 2013年 gdpuDeveloper. All rights reserved.
//

#import "AppsBaseViewController.h"
#import "AppDelegate.h"

@implementation AppsBaseViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (iPhone5) {
        [self.view setFrame:CGRectMake(0, 0, 320, 568)];
    }
    else {
        [self.view setFrame:CGRectMake(0, 0, 320, 480)];
    }
    
    if (ios7OrLater) {
        [self.navigationController.navigationBar setTranslucent:NO];
        [self.navigationController.navigationBar setBarTintColor:GetColorWithRGB(97, 42, 100)];//64, 193, 175
        self.edgesForExtendedLayout = UIRectEdgeNone;
        
        NSDictionary *dict = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
        self.navigationController.navigationBar.titleTextAttributes = dict;
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
        [self setNeedsStatusBarAppearanceUpdate];
    }
    else {
        [self.navigationController.navigationBar setTintColor:GetColorWithRGB(97, 42, 100)];
    }
    
    //监听键盘高度的变换
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    
    // 键盘高度变化通知，ios5.0新增的
#ifdef __IPHONE_5_0
    float version = [[[UIDevice currentDevice] systemVersion] floatValue];
    if (version >= 5.0) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillChangeFrameNotification object:nil];
    }
#endif
}

- (void)customBackButton {
    UIImage* image= [UIImage imageNamed:@"back_white_long.png"];
    CGRect frame_1= CGRectMake(0, 0, 80, 40);
    UIView *cView = [[UIView alloc] initWithFrame:frame_1];
    
    UIImageView *cImgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 40, 20)];
    [cImgView setImage:image];
    [cView addSubview:cImgView];
    
    UIButton* backButton= [[UIButton alloc] initWithFrame:frame_1];
    [backButton setBackgroundColor:[UIColor clearColor]];
    [backButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    [cView addSubview:backButton];
    
    //定制自己的风格的  UIBarButtonItem
    UIBarButtonItem* backItem= [[UIBarButtonItem alloc] initWithCustomView:cView];
    [self.navigationItem setLeftBarButtonItem:backItem];
    
    [self.navigationController.navigationBar setHidden:NO];
    [APP_DELEGATE setToolbarHidden:YES];
}

- (void)customNavigationBarRightButtonWithImageName:(NSString*)imgName {
    UIImage *btnImage = [UIImage imageNamed:imgName];
    if (!btnImage) {
        return;
    }
    //定制自己的风格的  UIBarButtonItem
    UIButton* jumpButton= [[UIButton alloc] initWithFrame:CGRectMake(0, 4, 34, 36)];//
    [jumpButton setBackgroundImage:btnImage forState:UIControlStateNormal];
    [jumpButton addTarget:self action:@selector(rightBarButtonAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* actionItem= [[UIBarButtonItem alloc] initWithCustomView:jumpButton];
    [self.navigationItem setRightBarButtonItem:actionItem];
}

- (void)customNavigationBarRightButtonWithTitleName:(NSString*)titleName {
    if (titleName && titleName.length > 0) {
        UIButton* jumpButton= [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];//
        [jumpButton setTitle:titleName forState:UIControlStateNormal];
        [jumpButton addTarget:self action:@selector(rightBarButtonAction) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem* actionItem= [[UIBarButtonItem alloc] initWithCustomView:jumpButton];
        [self.navigationItem setRightBarButtonItem:actionItem];
    }
}

- (void)goBack {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)rightBarButtonAction {
    NSLog(@"need to implement this methor");
}


#pragma mark - Responding to keyboard events
- (void)keyboardWillShow:(NSNotification *)notification {
    
}

- (void)keyboardWillHide:(NSNotification *)notification {
    
}



@end
